<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * Class Customer
 * @property CustomerDocking $docking
 * @package App\Models
 * @author luffyzhao@vip.126.com
 */
class Customer extends Model
{
    protected $fillable = ['code', 'name', 'phone', 'assure', 'contacts', 'remark'];


    protected static function boot()
    {
        static::addGlobalScope('orderBy', function (Builder $query) {
            $query->orderByDesc('id');
        });
        parent::boot();
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     * @author luffyzhao@vip.126.com
     */
    public function logs()
    {
        return $this->hasMany(CustomerInfoLogs::class, 'customer_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * @author luffyzhao@vip.126.com
     */
    public function docking()
    {
        return $this->hasOne(CustomerDocking::class);
    }

    /**
     * @return bool
     */
    public function isAvailable(){
        return $this->getAttribute('status') === 2;
    }


}
